package com.maven.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;


/*
 * restful风格的接口，根据get、post、put、delete等状态进行处理，同时在web.xml中添加配置项如下：
	<!-- configure the HiddenHttpMethodFilter,convert the post method to put or delete -->
	  <filter>
	      <filter-name>HiddenHttpMethodFilter</filter-name>
	      <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
	  </filter>
	  <filter-mapping>
	      <filter-name>HiddenHttpMethodFilter</filter-name>
	      <url-pattern>/*</url-pattern>
	  </filter-mapping>
 * */
@Controller
@RequestMapping("/rest")
public class RestController {
	
    /*
     * http://127.0.0.1:8080/maven-demo/rest/user/11
     * */
    @RequestMapping(value="/user/{id}",method=RequestMethod.GET)
    public String get(@PathVariable("id") Integer id){
        System.out.println("get"+id);
        return "/rest";
    }
    
    @RequestMapping(value="/user/{id}",method=RequestMethod.POST)
    public String post(@PathVariable("id") Integer id){
        System.out.println("post"+id);
        return "/rest";
    }
    
    @RequestMapping(value="/user/{id}",method=RequestMethod.PUT)
    public String put(@PathVariable("id") Integer id){
        System.out.println("put"+id);
        return "/rest";
    }
    
    @RequestMapping(value="/user/{id}",method=RequestMethod.DELETE)
    public String delete(@PathVariable("id") Integer id){
        System.out.println("delete"+id);
        return "/rest";
    }
    
}
